﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Transport;
using iLangl.Customer.Actions.Input;

namespace iLangl.Customer
{
	public class PushService : ITransport
	{

		public void SendRequest(UploadRequest request)
		{
			throw new NotImplementedException();
		}

		public UploadLightResponse SendRequestSync(UploadLightRequest request)
		{
			String packageData = request.PackageData;
			IPackage package = Facade.Instance.PackageManager.DispatchPackageFromString(packageData);

			IActionDescriptor descriptor = package.FindActionByName("PushAction");

			SynchronizeAction action = new SynchronizeAction();
			action.ResponseContext.SetContext(descriptor.ResponseContext.GetContext());
			action.Execute();

			IPackage responsepackage = Facade.Instance.PackageManager.CreateNewPackage();
			responsepackage.AddAction(action);


			UploadLightResponse response = new UploadLightResponse();
			response.Responses = new String[] { responsepackage.PackageBody };
			return response;
		}
	}
}
